package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.domain.ProBomMaterial;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProBom;
import com.ruoyi.mes.service.IProBomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * BOM管理Controller
 * 
 * @author CFL
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/mes/bom")
public class ProBomController extends BaseController
{
    @Autowired
    private IProBomService proBomService;

    /**
     * 查询BOM管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProBom proBom)
    {
        startPage();
        List<ProBom> list = proBomService.selectProBomList(proBom);
        return getDataTable(list);
    }

    /**
     * 导出BOM管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:export')")
    @Log(title = "BOM管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProBom proBom)
    {
        List<ProBom> list = proBomService.selectProBomList(proBom);
        ExcelUtil<ProBom> util = new ExcelUtil<ProBom>(ProBom.class);
        util.exportExcel(response, list, "BOM管理数据");
    }

    /**
     * 获取BOM管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(proBomService.selectProBomById(id));
    }

    /**
     * 获取BOM物料详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:mat:query')")
    @GetMapping(value = "/mat/{id}")
    public List<ProBomMaterial> getTableInfo(@PathVariable("id") Long id)
    {
        System.out.println(id+"亻尔女子end111:");
        return proBomService.selectProBomMat(id);
    }

    /**
     * 修改-根据产品id获取产品BOM物料详细信息
     */
    @GetMapping(value = "/material/{proId}")
    public List<ProBomMaterial> getProTableInfo(@PathVariable("proId") Long proId)
    {
        return proBomService.selectMaterialById(proId);
    }

    /**
     * 新增BOM管理
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:add')")
    @Log(title = "BOM管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProBom proBom)
    {
        return toAjax(proBomService.insertProBom(proBom));
    }

    /**
     * 修改BOM管理
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:edit')")
    @Log(title = "BOM管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProBom proBom)
    {
        return toAjax(proBomService.updateProBom(proBom));
    }

    /**
     * 删除BOM管理
     */
    @PreAuthorize("@ss.hasPermi('mes:bom:remove')")
    @Log(title = "BOM管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proBomService.deleteProBomByIds(ids));
    }
}
